-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix: Remove null values from JSON schemas to comply with JSON Schema #1698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@codex review this |
|
Overall, I feel this is a practical change. The only thing I'd like to confirm is that there is no edge case that could be affected by this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| # Remove all null values to comply with JSON Schema Draft 2020-12 | ||
| # This prevents LLM providers from rejecting schemas with null values | ||
| keys_to_remove = [] | ||
| for key, value in json_schema.items(): | ||
| if value is None: | ||
| keys_to_remove.append(key) | ||
|
|
||
| for key in keys_to_remove: | ||
| json_schema.pop(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Preserve strictness when additionalProperties is None
The new loop removes every key whose value is None. For object schemas that arrive with "additionalProperties": None, the earlier branch that defaults objects to additionalProperties=False is skipped because the key is present. After this block runs, the key is popped entirely, so the returned schema has no additionalProperties entry and therefore permits extra properties by default. This regresses the purpose of ensure_strict_json_schema, which should always disallow additional fields. Consider treating None as “not provided” before the object-type check or coercing it to False rather than dropping the key.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
|
I am not yet fully confident about having this change. It may break anything that are not mentioned here. I asked ChatGPT and got some suggestions. I don't follow these blindly, but just wanted to share it first. We may want to continue discussing and doing some research on a viable solution. Recommendations for
|
|
This PR is stale because it has been open for 10 days with no activity. |
|
This PR was closed because it has been inactive for 7 days since being marked as stale. |
When creating custom function tools, Pydantic models with optional fields defaulting to
Nonewere creating JSON schemas withnullvalues. This caused LLM providers to reject the schemas with errors like:Root cause: The
ensure_strict_json_schemafunction only removedNonefrom thedefaultfield, but left othernullvalues intact.Fix: Added logic to remove all
nullvalues from schemas to comply with JSON Schema Draft 2020-12.Test: Added test case verifying null values are properly stripped while preserving valid fields.